package com.church.daoimpl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.church.dao.UserDao;
import com.church.db.User;

public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

	@Override
	public void add(User user) {
		this.getHibernateTemplate().save(user);
	}

	@Override
	public void update(User user) {
		this.getHibernateTemplate().update(user);
	}

	@Override
	public void delete(User user) {
		this.getHibernateTemplate().delete(user);
	}

	@Override
	public User findByName(String name) {
		List<User> list = this.getHibernateTemplate().find(
				"from User where name='" + name + "'");
		if (list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<User> findByType(String type) {
		List<User> list = this.getHibernateTemplate().find(
				"from User where type='" + type + "'");
		return list;
	}

	@Override
	public List<User> getAllUser() {
		// TODO Auto-generated method stub
		return this.getHibernateTemplate().find("from User where state!='3'");
	}

	@Override
	public List<User> getUserByGroup(String group) {
		List<User> list = this.getHibernateTemplate().find(
				"from User where group='" + group + "'");
		return list;
	}

	@Override
	public User findById(long id) {
		List<User> list = this.getHibernateTemplate().find(
				"from User where id='" + id + "'");
		if (list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

}
